# 类似的字段有受保护和非受保护通过getter和setter定义
class Person(object):

    # 限定Person对象只能绑定_name, _age和_gender属性
    __slots__ = ('_name', '_age', '_gender')

    def __init__(self, name, age):
        self._name = name
        self._age = age

    @classmethod
    def now(cls): # cls表示当前类的实例
        return cls('王大锤', 12)

    #静态方法
    @staticmethod
    def staticfunc(a, b, c):
        return a + b > c and b + c > a and a + c > b

    # 访问器 - getter方法
    @property
    def name(self):
        return self._name

    # 访问器 - getter方法
    @property
    def age(self):
        return self._age

    # 修改器 - setter方法
    @age.setter
    def age(self, age):
        self._age = age

    def play(self):
        if self._age <= 16:
            print('%s正在玩飞行棋.' % self._name)
        else:
            print('%s正在玩斗地主.' % self._name)


def main():
    person = Person('王大锤', 12)
    person.play()
    person.age = 22
    person.play()
    # person.name = '白元芳'  # AttributeError: can't set attribute 受保护

    person._gender = '男'
    # person._is_gay = True # __slots__定义能赋值的字段，AttributeError: 'Person' object has no attribute '_is_gay'

    print(Person.staticfunc(1, 3, 4))

    Person.now()

if __name__ == '__main__':
    main()